学以致用 |
您所在的位置:网站首页 › 用vba 打开文件并复制内容到工作表中怎么操作不了 › 学以致用 |
需求描述:
为了方便管理大量的简历文件,需要将简历文件列表导入Excel中,然后筛选符合条件的简历,并直接在Excel中打开简历文件。 本段代码即可实现以下功能: 1. 支持用户根据实际情况(个人电脑中的文件系统)选择简历所在路径 2. 遍历指定文件夹,将其中的文件名及其路径分别写入工作表中 代码如下: Sub extractFileList_Rival() 'Developed by PDH on 20190720 Application.ScreenUpdating = False On Error Resume Next With Application.FileDialog(msoFileDialogFolderPicker) .InitialFileName = "Computer" .Show If .SelectedItems.Count > 0 Then myPath = .SelectedItems(1) Else Exit Sub End If End With Set fso = CreateObject("scripting.filesystemobject") Set ff = fso.getfolder(myPath) '遍历指定文件夹 ThisWorkbook.Sheets("CV").Columns("A:B").ClearContents ThisWorkbook.Sheets("CV").Cells(1, 1) = "File Name" ThisWorkbook.Sheets("CV").Cells(1, 2) = "Path" For Each f In ff.Files Cells(Rows.Count, 1).End(3).Offset(1) = f.Name '第一列最后一个有数据的单元格向下偏移一个单元格,1234分别对应左右上下(xlup, xldown, xltoleft, xltoright),3=xlup Cells(Rows.Count, 2).End(3).Offset(1) = Mid(f, 1, Len(f) - Len(f.Name) - 1) ' 获取文件对应的路径名 Next f If Cells(2, 1) = "" Then MsgBox "No file exists" End If Application.ScreenUpdating = True End Sub
|
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |